import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import './DesktopApp.dart' as Desktop;

import './lock_screen.dart' as lock_screen;
//main(List<String> args) {
//  runApp(Basewhidget());
//}

class Basewhidget extends StatelessWidget {
  // statelessWidget 是一个无状态的组件，用于自定义组件
  final arguments;
  Basewhidget({this.arguments});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // materialAPP 是作为根组件使用，定义该页面展示的总体布局
      home: Mybody({"cache":this.arguments["image"]}),
      theme: ThemeData(
        // 主题
          primarySwatch: Colors.blue // 颜色不能是block ，会报错
      ),
    );
  }
}

class Mybody extends StatefulWidget {
  final arguments;
  final map;
  Mybody(this.map, {this.arguments});

  @override
  _MybodyState createState() => _MybodyState(arguments: this.arguments, map: this.map);
}

class _MybodyState extends State<Mybody> {
  final arguments;
  final map;
  _MybodyState({this.arguments, this.map});
  var nows = new DateTime.now().toString();
  int isshow_index = 0;
  final cache_image = CachedNetworkImage(imageUrl: 'http://api.btstu.cn/sjbz/?lx=m_dongman&a=1&b=0',fit: BoxFit.cover,);

  int zm = 1;
  int sp = 0;
  String huos;
  String image_url = "http://api.btstu.cn/sjbz/?lx=m_dongman&a=1&b=2";
  List<TextStyle> isshow_textstyle = [TextStyle(color: Colors.white), TextStyle(color: Colors.white70)];

  void GetHous(){
    var nowTimes = DateTime.now();//获取当前时间
    var nowTime = nowTimes.toString();
    var hous = nowTime.substring(11, 16);
    this.huos = hous;
  }
  @override
  Widget build(BuildContext context) {
    this.image_url = map["cache"].imageUrl;
    print("aaabbbcccddd-------${arguments}, -----map ${map["cache"].imageUrl}");
    print(this.image_url);
    GetHous();
    var isshow = [lock_screen.GetLock(this.huos), Desktop.listv];
    return Scaffold(
      body: Container(
//        color: Colors.yellow,
        decoration: BoxDecoration(
//          image: this.cache_image;
          image: DecorationImage(
//            CachedNetworkImage(imageUrl: 'http://api.btstu.cn/sjbz/?lx=m_dongman&a=1&b=0',fit: BoxFit.cover,)
            // 设置全屏背景图片
            image: NetworkImage("http://api.btstu.cn/sjbz/?lx=m_dongman&a=1&b=0"),

            fit: BoxFit.cover,
          ),
        ),
        child: Column(
          children: <Widget>[
            Container(
              height: 200,
//              color: Colors.yellow,
              child: isshow[this.isshow_index],
            ),
            Spacer(),
            Container(
              height: 50,
//           color: Colors.yellow,
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Container(),
                  ),
                  Expanded(
                      child: FlatButton(
                        color: Colors.black26,
                        child: Text('锁屏预览',
                          textAlign: TextAlign.start,
                          style: this.isshow_textstyle[this.sp],
                        ),
                        onPressed: () {
                          print("锁屏预览被点击了");
                          setState(() {
                            GetHous();
                            this.sp = 0;
                            this.zm = 1;
                            this.isshow_index = 0;
                          });
                        },
                      )
                  ),
                  SizedBox(
                    width: 3,
                    height: 12,
                    child: DecoratedBox(
                      decoration: BoxDecoration(),
                    ),
                  ),

                  Expanded(

                      child: FlatButton(
                        color: Colors.black26,
                        child: new Text('桌面预览', textAlign: TextAlign.left,

                          style: this.isshow_textstyle[this.zm],
                        ),

                        onPressed: () {
                          print("桌面预览被点击了");

                          setState(() {
                            GetHous();
                            this.sp = 1;
                            this.zm = 0;
                            this.isshow_index = 1;
                          });

                        },
                      )

                  ),
                  Expanded(
                    child: Container(),
                  ),
                ],
              ),
            ),
            Container(
              height: 70,
//              color: Colors.blueAccent,

              child: Row(
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Container(),
                  ),

                  Expanded(
                      flex: 3,
                      child: FlatButton(
                        color: Colors.black26,
                        child: Text('设置为锁屏壁纸',
                          textAlign: TextAlign.start,
                          style: TextStyle(color: Colors.white),
                        ),
                        onPressed: () {
                          print("锁屏预览被点击了");
                          setState(() {
                            this.isshow_index = 0;
                          });
                        },
                      )
                  ),
                  SizedBox(
                    width: 40,
                    height: 12,
                    child: DecoratedBox(
                      decoration: BoxDecoration(),
                    ),
                  ),
                  Expanded(
                      flex: 3,
                      child: FlatButton(
                        color: Colors.black26,
                        child: new Text('设置为桌面壁纸', textAlign: TextAlign.left,
                          style: TextStyle(color: Colors.white70),
                        ),

                        onPressed: () {
                          print("桌面预览被点击了");
                        },
                      )

                  ),
                  SizedBox(
                    width: 40,
                    height: 12,
                    child: DecoratedBox(
                      decoration: BoxDecoration(),
                    ),
                  ),
                ],
              ),

            )
          ],
        ),
      ),
    );
  }
}
